package com.theo.controller;


import com.theo.entity.AjaxResponseInfo;
import com.theo.entity.CityInfo;
import com.theo.service.CityInfoService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 方涛
 * @since 2021-02-02
 */
@RestController
@RequestMapping("/city-info")
public class CityInfoController {
    @Autowired
    private CityInfoService cityInfoService;

    @GetMapping("/ajax/noDataList/{date}")
    public AjaxResponseInfo noDataProvinceList(@PathVariable("date") String date) {
        List<CityInfo> list = null;
        AjaxResponseInfo<List<CityInfo>> responseInfo = new AjaxResponseInfo<>();
        if (StringUtils.hasText(date)) {
            list = cityInfoService.findNoDataProvinces(date);
            responseInfo.setData(list);
        } else {
            responseInfo.setCode(-1);
            responseInfo.setMsg("参数出错");
        }
        return responseInfo;
    }

    @RequestMapping("/ajax/allProvinces")
    public AjaxResponseInfo allProvinces() {
        List<CityInfo> provinces = cityInfoService.findProvinces();
        AjaxResponseInfo<List<CityInfo>> responseInfo = new AjaxResponseInfo<>();
        responseInfo.setData(provinces);
        return responseInfo;
    }

    @RequestMapping("/ajax/allCities")
    public AjaxResponseInfo allCities(Integer id) {
        List<CityInfo> cities = cityInfoService.findCities(id);
        AjaxResponseInfo<List<CityInfo>> responseInfo = new AjaxResponseInfo<>();
        responseInfo.setData(cities);
        return responseInfo;
    }
}

